#!/usr/bin/python

import pycurl, StringIO

# Constants
USER_AGENT = 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.1) Gecko/2008071620 Firefox/3.0.1'
LOGIN_URL = 'http://test-pfa.forumgratuit.fr/'
POST_DATA = 'username=admin&password=exploder53&submitButton=login'
HEADERS = ['Accept-Language: en-us,en;q=0.5', 'Accept-Encoding: gzip,deflate', 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'Keep-Alive: 300', 'Connection: Keep-Alive']

POST_URL = 'http://test-pfa.forumgratuit.fr/post?t=1&mode=reply/'
POST_TEST_DATA = 'subject=premierStestSviaSscript&message=allez'
# Request post page
dev_null = StringIO.StringIO()
pycurlConnect = pycurl.Curl()
pycurlConnect.setopt(pycurl.URL, LOGIN_URL)
#pycurlConnect.setopt(pycurl.REFERER, REFERER)
pycurlConnect.setopt(pycurl.POSTFIELDS, POST_DATA)
pycurlConnect.setopt(pycurl.WRITEFUNCTION, dev_null.write)
pycurlConnect.setopt(pycurl.COOKIEFILE, 'cookies.txt')
pycurlConnect.setopt(pycurl.POST, 1)
pycurlConnect.setopt(pycurl.VERBOSE, 1)
#pycurlConnect.perform()
pycurlConnect.setopt(pycurl.URL, POST_URL)
#pycurlConnect.setopt(pycurl.REFERER, REFERER)
pycurlConnect.setopt(pycurl.POSTFIELDS, POST_TEST_DATA)
pycurlConnect.setopt(pycurl.WRITEFUNCTION, dev_null.write)
pycurlConnect.setopt(pycurl.COOKIEFILE, 'cookies.txt')
pycurlConnect.setopt(pycurl.POST, 1)
pycurlConnect.setopt(pycurl.VERBOSE, 1)
pycurlConnect.perform()

# Close connections
dev_null.close()
pycurlConnect.close()
